home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume7 / nethack3 / patch6b < prev    next >
Encoding:
Internet Message Format  |  1989-11-27  |  61.0 KB

  1. Path: uunet!zephyr.ens.tek.com!tekgen!tekred!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v08i055:  NetHack3 -  display oriented dungeons & dragons (Ver. 3.0), Patch6b
  5. Message-ID: <4844@tekred.CNA.TEK.COM>
  6. Date: 22 Nov 89 19:46:15 GMT
  7. Sender: nobody@tekred.CNA.TEK.COM
  8. Lines: 2051
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: Izchak Miller <izchak@linc.cis.upenn.edu>
  12. Posting-number: Volume 8, Issue 55
  13. Archive-name: NetHack3/Patch6b
  14. Patch-To: NetHack3: Volume 7, Issue 56-93
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 2 (of 15)."
  25. # Contents:  patches06d
  26. # Wrapped by billr@saab on Wed Nov 22 10:50:06 1989
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'patches06d' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'patches06d'\"
  30. else
  31. echo shar: Extracting \"'patches06d'\" \(58568 characters\)
  32. sed "s/^X//" >'patches06d' <<'END_OF_FILE'
  33. X*** /dev/null    Sun Nov 19 14:15:21 1989
  34. X--- others/ovlmgr.asm    Sat Nov 18 17:17:30 1989
  35. X***************
  36. X*** 0 ****
  37. X--- 1,1179 ----
  38. X+ ;    SCCS Id: @(#)ovlmgr.asm     3.0    89/11/16
  39. X+ ;  Copyright (c) Pierre Martineau and Stephen Spackman, 1989.
  40. X+ ;  This product may be freely redistributed.  See NetHack license for details.
  41. X+ 
  42. X+         PAGE    60,132
  43. X+         TITLE    'Overlay manager for use with Microsoft overlay linker'
  44. X+         SUBTTL    'Brought to you by Pierre Martineau and Stephen Spackman'
  45. X+ 
  46. X+ ; acknowledgements:   - No thanks to Microsoft
  47. X+ ;              - alltrsidsctysti!!!
  48. X+ ;              - izchak and friends for impetus
  49. X+ ;              - us for brilliance
  50. X+ ;              - coffee for speed
  51. X+ ;              - others as necessary
  52. X+ 
  53. X+ ; assumptions:          - all registers are preserved including flags
  54. X+ ;              - the stack is preserved
  55. X+ ;              - re-entrancy is not required
  56. X+ 
  57. X+ DOSALLOC    equ    48h            ; memory allocation
  58. X+ DOSFREE     equ    49h            ; free allocated memory
  59. X+ DOSREALLOC    equ    4ah            ; modify memory block
  60. X+ DOSREAD     equ    3fh            ; read bytes from handle
  61. X+ DOSSEEK     equ    42h            ; logical handle seek
  62. X+ DOSOPEN     equ    3dh            ; open handle
  63. X+ DOSCLOSE    equ    3eh            ; close handle
  64. X+ DOSGETVEC    equ    35h            ; get interrupt vector
  65. X+ DOSSETVEC    equ    25h            ; set interrupt vector
  66. X+ DOSEXEC     equ    4bh            ; exec child process
  67. X+ DOS        equ    21h            ; Dos interrupt #
  68. X+ PRINT        equ    09h            ; print string
  69. X+ TERMINATE    equ    4ch            ; terminate process
  70. X+ CR        equ    0dh
  71. X+ LF        equ    0ah
  72. X+ BELL        equ    07h
  73. X+ FAERIE        equ    0h            ; Used for dummy segment allocation
  74. X+ PARSIZ        equ    10h            ; this is the size of a paragraph - this better not change!
  75. X+ 
  76. X+ ; The following extrns are supplied by the linker
  77. X+ 
  78. X+ extrn        $$OVLBASE:byte            ; segment of OVERLAY_AREA
  79. X+ extrn        $$MPGSNOVL:byte         ; ^ to module table
  80. X+ extrn        $$MPGSNBASE:word        ; ^ to module segment fixups
  81. X+ extrn        $$INTNO:byte            ; interrupt number to be used
  82. X+ extrn        $$COVL:word            ; number of physical overlays
  83. X+ extrn        $$CGSN:word            ; number of modules
  84. X+ extrn        $$MAIN:far            ; ^ to function main()
  85. X+ 
  86. X+ public        $$OVLINIT            ; Our entry point
  87. X+                         ; called by the c startup code
  88. X+ 
  89. X+ ovlflgrec    record    running:1=0,locked:1=0,loaded:1=0 ; overlay flags
  90. X+ 
  91. X+ ; This is a dirty hack. What we need is a virtual segment that will be built
  92. X+ ; by the (our) loader in multiple copies, one per overlay. Unfortunately, this
  93. X+ ; doesn't seem to be a sensible idea in the minds of the folks at Microsoft.
  94. X+ ; Declaring this segment AT will ensure that it never appears in the exefile,
  95. X+ ; and ASSUME is dumb enough to be fooled.
  96. X+ ;
  97. X+ ; The reason we want to do this is also not-to-be-tried-at-home: it turns out
  98. X+ ; that we can code a faster interrupt handler if we map overlay numbers to
  99. X+ ; segment values. Normally I would consider this unacceptable programming
  100. X+ ; practise because it is 86-mode specific, but the *need* for this entire
  101. X+ ; programme is 86-mode specific, anyway.
  102. X+ 
  103. X+ pspseg        segment para at FAERIE        ; dummy segment for psp
  104. X+         org    2ch            ; ^ to segment of environmemt in psp
  105. X+ pspenv        LABEL    WORD
  106. X+ pspseg        ends
  107. X+ 
  108. X+ ovltbl        segment para at FAERIE        ; Dummy segment definition for overlay table
  109. X+ 
  110. X+ ; NOTE: This segment definition MUST be exactly 16 bytes long
  111. X+ 
  112. X+ ovlflg        ovlflgrec    <0,0,0>     ; overlay flags
  113. X+ ovltblpad1    db    ?            ; go ahead, delete me!
  114. X+ ovlmemblk    dw    ?            ; ^ to allocated memory block
  115. X+ ovlseg        dw    0            ; ovl segment physical add.
  116. X+ ovlfiloff    dw    ?            ; ovl file offset in pages (512 bytes)
  117. X+ ovlsiz        dw    ?            ; ovl size in paragraphs
  118. X+ ovllrudat    dd    0            ; misc lru data (pseudo time stamp)
  119. X+ ovltblpad2    dw    ?            ; go ahead, delete me!
  120. X+ 
  121. X+ if1
  122. X+ if        $ gt PARSIZ
  123. X+         .err
  124. X+         %out This segment MUST be no more than 16 bytes, REALLY!!!
  125. X+ endif
  126. X+ endif
  127. X+ 
  128. X+ ovlsegsiz    equ    PARSIZ            ; this had better be true!!! (16 bytes)
  129. X+ 
  130. X+ ovltbl        ends
  131. X+ 
  132. X+ EXEHDR        struc                ; structure of an EXE header
  133. X+ exesign     dw    5a4dh            ; signature
  134. X+ exelstpgesiz    dw    ?            ; last page size (512 byte pages)
  135. X+ exesiz        dw    ?            ; total pages (including partial last page)
  136. X+ relocitems    dw    ?            ; number of relocation entries
  137. X+ hdrparas    dw    ?            ; number of paragraphs in the header
  138. X+ minalloc    dw    ?            ; minimum paragraph allocation
  139. X+ maxalloc    dw    ?            ; maximum patagraph allocation
  140. X+ exess        dw    ?            ; initial stack segment
  141. X+ exesp        dw    ?            ; initial stack pointer
  142. X+ exechksum    dw    ?            ; checksum
  143. X+ exeip        dw    ?            ; initial instruction pointer
  144. X+ execs        dw    ?            ; initial code segment
  145. X+ reloctbloff    dw    ?            ; offset from beginning of header to relocation table
  146. X+ exeovlnum    dw    ?            ; overlay number
  147. X+ EXEHDR        ends
  148. X+ 
  149. X+ MASK_used    equ    1            ; memory block flag
  150. X+ 
  151. X+ memctlblk    struc                ; memory block structure
  152. X+ memblkflg    db    0            ; flags
  153. X+ memblkpad1    db    0            ; go ahead, delete me!
  154. X+ memblknxt    dw    0            ; ^ to next block
  155. X+ memblkprv    dw    0            ; ^ to previous block
  156. X+ memblkovl    dw    0            ; ^ to overlay occupying this block
  157. X+ memblksiz    dw    0            ; size in paragraphs
  158. X+ memblkpad    db    PARSIZ - ($ - memblkflg) mod parsiz dup (?) ; pad to 16 bytes
  159. X+ memctlblk    ends
  160. X+ 
  161. X+ memctlblksiz    equ    memblkpad + SIZE memblkpad ; should equal 1 paragraph (16 bytes)
  162. X+ 
  163. X+ ;-------------------------------------------------------------------------------
  164. X+ 
  165. X+ code        segment public
  166. X+ 
  167. X+ ovlexefilhdl    dw    -1            ; always-open file handle of our .EXE
  168. X+ ovltim        dd    0            ; pseudo-lru time variable
  169. X+ curovl        dw    offset framestk     ; ^ into stack frame
  170. X+ ovlcnt        dw    0            ; # overlays
  171. X+ modcnt        dw    0            ; # of modules
  172. X+ ovltblbse    dw    -1            ; segment of first overlay descriptor
  173. X+ ovlrootcode    dw    0            ; logical segment of OVERLAY_AREA
  174. X+ ovldata     dw    0            ; logical segment of OVERLAY_END
  175. X+ memblk1st    dw    0            ; first memory block
  176. X+ pspadd        dw    0            ; our psp address + 10h (for relocations)
  177. X+ oldvec        dd    -1            ; saved interrupt vector
  178. X+ oldint21    dd    -1            ; saved int 21 vector
  179. X+ memstat     db    0ffh            ; must we re-allocate some memory
  180. X+ bxreg        dw    0            ; temp save area
  181. X+ esreg        dw    0            ; temp save area
  182. X+ farcall     dd    0            ; internal trampoline.
  183. X+ hdr        EXEHDR    <>            ; EXE header work area
  184. X+ hdrsize     equ    $ - hdr
  185. X+ 
  186. X+ framestk    dw    100h dup (0)        ; internal stack
  187. X+ 
  188. X+ moduletbl    dw    256*2 dup (0)        ; module lookup table
  189. X+ 
  190. X+ noroom        db    CR,LF,'Not enough memory to run this program.  Time to go to the store.',CR,LF,BELL,'$'
  191. X+ nocore        db    CR,LF,'Your dog eats all your remaining memory!  You die.',CR,LF,BELL,'$'
  192. X+ nofile        db    CR,LF,'The Nymph stole your .EXE file!  You die.',CR,LF,BELL,'$'
  193. X+ exitmsg     db    CR,LF,'$'
  194. X+ 
  195. X+ ;-------------------------------------------------------------------------------
  196. X+ 
  197. X+ $$OVLINIT    proc    far            ; Init entry point
  198. X+ 
  199. X+         assume    cs:code,ds:pspseg,es:nothing
  200. X+ 
  201. X+         push    ax
  202. X+         push    bx
  203. X+         push    cx
  204. X+         push    dx
  205. X+         push    si
  206. X+         push    di
  207. X+         push    bp
  208. X+         push    ds
  209. X+         push    es            ; save the world
  210. X+         mov    ax,ds            ; get our psp
  211. X+         add    ax,10h
  212. X+         mov    pspadd,ax        ; save it
  213. X+         mov    ds,pspenv        ; get environment segment
  214. X+         mov    si,-1
  215. X+ envloop:                    ; search for end of environment
  216. X+         inc    si
  217. X+         cmp    word ptr [si],0
  218. X+         jnz    envloop
  219. X+         add    si,4            ; point to EXE filename
  220. X+         mov    al,0            ; access code
  221. X+         mov    ah,DOSOPEN
  222. X+         mov    dx,si
  223. X+         int    DOS            ; open EXE
  224. X+         jnc    dontdie
  225. X+         mov    al,5
  226. X+         mov    dx,offset nofile
  227. X+         jmp    putserr         ; cry to the world!
  228. X+ dontdie:
  229. X+         mov    ovlexefilhdl,ax     ; save handle
  230. X+         mov    ax,SEG $$OVLBASE    ; OVERLAY_AREA segment
  231. X+         mov    ovlrootcode,ax
  232. X+ 
  233. X+ ; Now allocate memory
  234. X+         mov    bx,0900h        ; allocate memory for malloc()
  235. X+         mov    ah,DOSALLOC
  236. X+         int    DOS
  237. X+         jnc    getmore
  238. X+         jmp    buyram
  239. X+ getmore:
  240. X+         mov    es,ax            ; find largest free memory
  241. X+         mov    ah,DOSALLOC
  242. X+         mov    bx,0ffffh        ; Everything
  243. X+         int    DOS
  244. X+         mov    ah,DOSALLOC        ; allocate our own memory
  245. X+         int    DOS
  246. X+         jnc    gotitall
  247. X+         jmp    buyram
  248. X+ gotitall:
  249. X+         mov    memstat,0        ; indicate that we have memory
  250. X+         mov    ovltblbse,ax        ; overlay descriptor table begins at start of memory block
  251. X+         mov    ax,SEG $$COVL        ; segment of DGROUP
  252. X+         mov    ds,ax
  253. X+         mov    cx,$$CGSN        ; number of modules
  254. X+         mov    modcnt,cx        ; save for later use
  255. X+         mov    cx,$$COVL        ; number of physical overlays
  256. X+         mov    ovlcnt,cx        ; save for later use
  257. X+         sub    bx,cx            ; enough mem for ovl tbl?
  258. X+         jnc    memloop
  259. X+         jmp    buyram
  260. X+ memloop:
  261. X+         push    bx
  262. X+         mov    ah,DOSFREE        ; free first block for malloc()
  263. X+         int    DOS
  264. X+         jnc    cockadoodledoo
  265. X+         jmp    buyram
  266. X+ cockadoodledoo:
  267. X+ 
  268. X+         assume    es:ovltbl
  269. X+ 
  270. X+         xor    bp,bp
  271. X+         xor    di,di
  272. X+         xor    si,si
  273. X+ filsegtbllpp:                    ; initialise ovl table
  274. X+         call    gethdr            ; get an EXE header
  275. X+         mov    ax,ovltblbse
  276. X+         add    ax,hdr.exeovlnum
  277. X+         mov    es,ax            ; ^ to ovl table entry
  278. X+         xor    ax,ax
  279. X+         mov    word ptr ovllrudat,ax    ; initialise ovl lru
  280. X+         mov    word ptr ovllrudat+2,ax
  281. X+         mov    ovlseg,ax        ; initialise ovl segment
  282. X+         mov    ovlflg,al        ; initialise ovl flags
  283. X+         mov    ax,hdr.exesiz
  284. X+         shl    ax,1
  285. X+         shl    ax,1
  286. X+         shl    ax,1
  287. X+         shl    ax,1
  288. X+         shl    ax,1            ; * 32
  289. X+         mov    dx,hdr.exelstpgesiz
  290. X+         or    dx,dx
  291. X+         jz    emptypage
  292. X+         shr    dx,1
  293. X+         shr    dx,1
  294. X+         shr    dx,1
  295. X+         shr    dx,1            ; / 16
  296. X+         inc    dx
  297. X+         sub    ax,20h
  298. X+         add    ax,dx
  299. X+ emptypage:
  300. X+         mov    ovlsiz,ax        ; overlay size in paragraphs
  301. X+         sub    ax,hdr.hdrparas     ; actual size of code and relocation table
  302. X+         cmp    hdr.exeovlnum,0     ; skip if ovl 0 (root code)
  303. X+         jz    notlargest
  304. X+         cmp    ax,di            ; find largest ovl
  305. X+         jc    notlargest
  306. X+         mov    di,ax
  307. X+         mov    si,ovlsiz
  308. X+ notlargest:
  309. X+         mov    ovlfiloff,bp        ; initialise ovl file offset
  310. X+         add    bp,hdr.exesiz        ; ^ to next overlay
  311. X+         mov    dx,bp
  312. X+         mov    cl,dh
  313. X+         mov    dh,dl
  314. X+         xor    ch,ch
  315. X+         xor    dl,dl
  316. X+         shl    dx,1
  317. X+         rcl    cx,1            ; cx:dx = bp * 512
  318. X+         mov    al,0
  319. X+         mov    ah,DOSSEEK        ; seek to next ovl
  320. X+         int    DOS
  321. X+         mov    ax,ovlcnt
  322. X+         dec    ax
  323. X+         cmp    ax,hdr.exeovlnum    ; all overlays done?
  324. X+         jz    makmemblk
  325. X+         jmp    filsegtbllpp        ; Nope, go for more.
  326. X+ makmemblk:
  327. X+         push    si            ; contains largest ovl size in paragraphs
  328. X+ 
  329. X+         assume    es:nothing        ; prepare first two memory blocks
  330. X+                         ; OVERLAY_AREA and allocated memory block
  331. X+         mov    ax,ovlrootcode        ; OVERLAY_AREA segment
  332. X+         mov    es,ax
  333. X+         mov    si,ovltblbse
  334. X+         add    si,ovlcnt        ; end of ovl table
  335. X+         mov    es:memblkflg,0        ; clear mem flags
  336. X+         mov    es:memblknxt,si     ; point to next
  337. X+         mov    es:memblkprv,0        ; set previous to nothing
  338. X+         mov    es:memblksiz,di     ; di contains OVERLAY_AREA size in paragraphs
  339. X+         add    di,ax
  340. X+         mov    ovldata,di        ; end of OVERLAY_END
  341. X+         mov    es,si            ; end of ovl tbl (first memory block in allocated memory)
  342. X+         mov    es:memblkflg,0        ; clear mem flags
  343. X+         mov    es:memblknxt,0        ; set next to nothing
  344. X+         mov    es:memblkprv,ax     ; point to previous
  345. X+         pop    si
  346. X+         pop    bx
  347. X+         mov    es:memblksiz,bx     ; allocated memory block size less ovl table
  348. X+         mov    memblk1st,ax        ; save pointer to first mem block
  349. X+         mov    word ptr ovltim,0    ; initialise global lru time stamp
  350. X+         mov    word ptr ovltim+2,0
  351. X+         mov    ax,offset framestk
  352. X+         mov    curovl,ax        ; initialise stack frame pointer
  353. X+         mov    di,ax
  354. X+         mov    word ptr cs:[di],-1    ; initialise stack frame
  355. X+         add    di,6
  356. X+         mov    ax,ovltblbse
  357. X+         mov    cs:[di],ax
  358. X+         mov    curovl,di
  359. X+         mov    es,ax
  360. X+         mov    es:ovlflg,MASK running OR MASK locked OR MASK loaded ; set flags on ovl 0
  361. X+         inc    si            ; largest ovl size + 1 paragraph
  362. X+         cmp    bx,si            ; enough memory to alloc largest?
  363. X+         jnc    chgintvec
  364. X+ buyram:
  365. X+         mov    al,5
  366. X+         mov    dx,OFFSET noroom    ; free up some TSRs or something
  367. X+         jmp    putserr
  368. X+ chgintvec:
  369. X+         mov    ax,SEG $$INTNO
  370. X+         mov    ds,ax
  371. X+         mov    ah,DOSGETVEC
  372. X+         mov    al,$$INTNO        ; get int number to use
  373. X+         int    DOS            ; get original vector
  374. X+         mov    word ptr oldvec,bx    ; save original vector
  375. X+         mov    word ptr oldvec+2,es
  376. X+ 
  377. X+         mov    ah,DOSGETVEC
  378. X+         mov    al,21h
  379. X+         int    DOS            ; get original vector
  380. X+         mov    word ptr oldint21,bx    ; save original vector
  381. X+         mov    word ptr oldint21+2,es
  382. X+ 
  383. X+         mov    ax,SEG $$INTNO
  384. X+         mov    ds,ax
  385. X+         mov    ah,DOSSETVEC
  386. X+         mov    al,$$INTNO
  387. X+         mov    bx,cs
  388. X+         mov    ds,bx
  389. X+         mov    dx,OFFSET ovlmgr    ; point to ovlmgr
  390. X+         int    DOS            ; set vector
  391. X+ 
  392. X+         mov    ah,DOSSETVEC
  393. X+         mov    al,21h
  394. X+         mov    bx,cs
  395. X+         mov    ds,bx
  396. X+         mov    dx,OFFSET int21     ; point to int21
  397. X+         int    DOS            ; set vector
  398. X+ 
  399. X+         mov    cx,modcnt        ; module count
  400. X+         mov    ax,SEG $$MPGSNBASE
  401. X+         mov    es,ax
  402. X+         mov    ax,cs
  403. X+         mov    ds,ax
  404. X+ 
  405. X+         assume    ds:code
  406. X+ 
  407. X+         mov    bx,offset $$MPGSNBASE    ; ^ to linker provided overlay segment fixups
  408. X+         mov    si,offset $$MPGSNOVL    ; ^ to linker provided module table
  409. X+         mov    di,offset moduletbl    ; ^ to our module table
  410. X+ modloop:
  411. X+         mov    al,es:[si]        ; real physical ovl number
  412. X+         xor    ah,ah
  413. X+         add    ax,ovltblbse        ; ovlctlseg address
  414. X+         mov    [di],ax         ; save in module table
  415. X+         mov    ax,es:[bx]        ; get seg fixup
  416. X+         sub    ax,ovlrootcode        ; adjust for relative reference
  417. X+         mov    [di+2],ax        ; save in module table
  418. X+         add    di,4
  419. X+         add    bx,2
  420. X+         inc    si
  421. X+         loop    modloop
  422. X+ 
  423. X+         pop    es
  424. X+         pop    ds
  425. X+         pop    bp
  426. X+         pop    di
  427. X+         pop    si
  428. X+         pop    dx
  429. X+         pop    cx
  430. X+         pop    bx
  431. X+         pop    ax            ; restore the world
  432. X+         jmp    $$MAIN            ; And away we go!
  433. X+ 
  434. X+ $$OVLINIT    endp
  435. X+ 
  436. X+ ;-------------------------------------------------------------------------------
  437. X+ 
  438. X+ ovlmgr        proc    far            ; This the it!
  439. X+ 
  440. X+         assume cs:code,ds:nothing,es:nothing
  441. X+ 
  442. X+         mov    bxreg,bx        ; preserve bx
  443. X+         mov    esreg,es        ; and es
  444. X+         pop    bx            ; retrieve caller ip
  445. X+         pop    es            ;     "      "    cs
  446. X+         push    ax
  447. X+         push    si
  448. X+         mov    ax,es:[bx+1]        ; offset in ovl to call
  449. X+         mov    word ptr farcall,ax    ; into trampoline
  450. X+         xor    ah,ah
  451. X+         mov    al,es:[bx]        ; module # to call
  452. X+         add    bx,3            ; fix return address
  453. X+         mov    si,curovl        ; get stack frame pointer
  454. X+         mov    cs:[si+2],es        ; save return seg
  455. X+         mov    cs:[si+4],bx        ; and return offset
  456. X+ 
  457. X+         mov    bx,ax
  458. X+         shl    bx,1
  459. X+         shl    bx,1            ; * 4 (2 words/entry in module tbl)
  460. X+         add    bx,offset moduletbl
  461. X+         mov    es,cs:[bx]        ; ovl tbl entry
  462. X+         mov    ax,cs:[bx+2]        ; segment fixup
  463. X+         mov    cs:[si+6],es        ; ovl entry into stack frame
  464. X+         add    curovl,6        ; update stack
  465. X+ 
  466. X+         assume    es:ovltbl
  467. X+ 
  468. X+         mov    si,WORD PTR ovltim    ; lru time stamp
  469. X+         inc    si            ; time passes!
  470. X+         mov    WORD PTR ovltim,si    ; update global clock
  471. X+         mov    WORD PTR ovllrudat,si    ; as well as ovl clock
  472. X+         jz    ininc            ; dword increment
  473. X+ cryupcdon:    test    ovlflg,mask loaded    ; ovl loaded?
  474. X+         jz    inload            ; load it then.
  475. X+ ovlloadedupc:
  476. X+         add    ax,ovlseg        ; add fixup and segment address
  477. X+         mov    word ptr farcall+2,ax    ; into trampoline
  478. X+         mov    bx,bxreg        ; retore all registers
  479. X+         mov    es,esreg
  480. X+         pop    si
  481. X+         pop    ax
  482. X+         popf                ; don't forget these!
  483. X+         call    DWORD PTR farcall    ; and GO
  484. X+         pushf                ; preserve registers again!
  485. X+         mov    esreg,es
  486. X+         mov    bxreg,bx
  487. X+         mov    bx,curovl        ; stack frame pointer
  488. X+         mov    es,cs:[bx-6]        ; retrieve ovl tbl entry
  489. X+         push    cs:[bx-4]        ; set return address
  490. X+         push    cs:[bx-2]
  491. X+         push    cx
  492. X+         mov    cx,WORD PTR ovltim    ; do the lru thing again
  493. X+         inc    cx
  494. X+         mov    WORD PTR ovltim,cx
  495. X+         mov    WORD PTR ovllrudat,cx
  496. X+         jz    outinc
  497. X+ crydncdon:    test    ovlflg,mask loaded    ; ovl loaded?
  498. X+         jz    outload         ; better get it before someone notices
  499. X+ jmpback:
  500. X+         sub    curovl,6        ; adjust stack
  501. X+         mov    bx,bxreg        ; get registers back
  502. X+         mov    es,esreg
  503. X+         pop    cx
  504. X+         iret                ; and GO back
  505. X+ 
  506. X+ ininc:
  507. X+         mov    si,WORD PTR ovltim+2    ; high word of lru
  508. X+         inc    si
  509. X+         mov    WORD PTR ovltim+2,si    ; update global and
  510. X+         mov    WORD PTR ovllrudat+2,si ; ovl clocks
  511. X+         jmp    cryupcdon
  512. X+ 
  513. X+ inload:
  514. X+         call    loadoverlay        ; self explanatory
  515. X+         jmp    ovlloadedupc
  516. X+ 
  517. X+ outinc:
  518. X+         mov    cx,WORD PTR ovltim+2
  519. X+         inc    cx
  520. X+         mov    WORD PTR ovltim+2,cx
  521. X+         mov    WORD PTR ovllrudat+2,cx
  522. X+         jmp    crydncdon
  523. X+ 
  524. X+ outload:
  525. X+         call    loadoverlay
  526. X+         jmp    jmpback
  527. X+ 
  528. X+ ovlmgr        endp
  529. X+ 
  530. X+ ;-------------------------------------------------------------------------------
  531. X+ 
  532. X+ loadoverlay    proc    near            ; load overlay pointed to by es
  533. X+ 
  534. X+         assume    cs:code,ds:nothing,es:ovltbl
  535. X+ 
  536. X+         push    ax
  537. X+         push    bx
  538. X+         push    cx
  539. X+         push    dx
  540. X+         push    si
  541. X+         push    di
  542. X+         push    bp
  543. X+         push    ds
  544. X+         push    es            ; just in case
  545. X+         cmp    memstat,0
  546. X+         jz    dontrealloc
  547. X+         call    reallocmem
  548. X+ dontrealloc:
  549. X+         call    setrunning        ; set the running flags
  550. X+         test    ovlflg,MASK running    ; was it already running?
  551. X+         jnz    fxdadr            ; Yup, it's a toughie
  552. X+         mov    ax,ovlsiz        ; How much?
  553. X+         call    getpages        ; never fail mem alloc, you bet.
  554. X+         jmp    gleaner
  555. X+ fxdadr:
  556. X+         call    releasepages        ; free memory where this ovl should be loaded
  557. X+ gleaner:
  558. X+         mov    ovlmemblk,ax        ; memory block to use
  559. X+         add    ax,memctlblksiz / PARSIZ; skip mem ctl blk
  560. X+         mov    ds,ax
  561. X+         mov    dx,ovlfiloff        ; where in the file is it?
  562. X+         mov    cl,dh
  563. X+         mov    dh,dl
  564. X+         xor    ch,ch
  565. X+         xor    dl,dl
  566. X+         shl    dx,1
  567. X+         rcl    cx,1            ; cx:dx = dx * 512
  568. X+         mov    ah,DOSSEEK        ; lseek to position
  569. X+         mov    al,0
  570. X+         mov    bx,ovlexefilhdl     ; never closing handle
  571. X+         int    DOS
  572. X+         jc    burnhead        ; oops!
  573. X+         xor    dx,dx
  574. X+         mov    cx,ovlsiz        ; number of paragraphs to load
  575. X+         shl    cx,1
  576. X+         shl    cx,1
  577. X+         shl    cx,1
  578. X+         shl    cx,1            ; * 16 = number of bytes
  579. X+         mov    ah,DOSREAD        ; prevent random DOS behaviour
  580. X+         int    DOS
  581. X+         jc    burnhead        ; double oops!
  582. X+         call    ovlrlc            ; perform relocation normally done by DOS EXE loader
  583. X+         pop    es            ; retrieve ovl tbl entry
  584. X+         or    ovlflg,MASK loaded    ; because it is now
  585. X+         pop    ds
  586. X+         pop    bp
  587. X+         pop    di
  588. X+         pop    si
  589. X+         pop    dx
  590. X+         pop    cx
  591. X+         pop    bx
  592. X+         pop    ax
  593. X+         ret
  594. X+ 
  595. X+ burnhead:
  596. X+         mov    al,5
  597. X+         mov    dx,offset nofile
  598. X+         jmp    putserr
  599. X+ 
  600. X+ loadoverlay    endp
  601. X+ 
  602. X+ ;-------------------------------------------------------------------------------
  603. X+ 
  604. X+ ovlrlc        proc    near            ; ds:0 -> the overlay to relocate
  605. X+ 
  606. X+         assume    cs:code,ds:nothing,es:ovltbl
  607. X+ 
  608. X+         mov    cx,ds:relocitems    ; roto-count
  609. X+         mov    ax,ds
  610. X+         add    ax,ds:hdrparas        ; skip header
  611. X+         mov    ovlseg,ax        ; actual code starts here
  612. X+         mov    di,ax
  613. X+         sub    di,ovlrootcode        ; segment fixup value
  614. X+         mov    si,ds:reloctbloff    ; ^ relocation tbl in header
  615. X+         jcxz    relocdone        ; not such a good idea, after all
  616. X+ dorelocs:                    ; labels don't GET comments
  617. X+         lodsw                ; offset into load module
  618. X+         mov    bx,ax
  619. X+         lodsw                ; segment in load module (zero reference)
  620. X+         add    ax,pspadd        ; now it is psp relative
  621. X+         add    ax,di            ; and now it is relative to the actual load address
  622. X+         mov    es,ax
  623. X+         mov    ax,es:[bx]        ; pickup item to relocate
  624. X+         add    ax,pspadd        ; make it psp relative
  625. X+         cmp    ax,ovlrootcode        ; is it below the OVERLAY_AREA?
  626. X+         jc    reloccomputed        ; yup. it's relocated
  627. X+         cmp    ax,ovldata        ; is it above OVERLAY_AREA
  628. X+         jnc    reloccomputed        ; yup. it's relocated
  629. X+         add    ax,di            ; it's in OVERLAY_AREA, this one's ours.
  630. X+ reloccomputed:
  631. X+         mov    es:[bx],ax        ; RAM it home!?!
  632. X+         loop    dorelocs        ; what goes around, comes around.
  633. X+ relocdone:    ret
  634. X+ 
  635. X+ ovlrlc        endp
  636. X+ 
  637. X+ ;-------------------------------------------------------------------------------
  638. X+ 
  639. X+ getvictim    proc    near            ; select a victim to discard (and free up some memory)
  640. X+ 
  641. X+         assume    cs:code,ds:ovltbl,es:nothing
  642. X+ 
  643. X+         push    bx
  644. X+         push    cx
  645. X+         push    dx
  646. X+         push    si
  647. X+         push    di
  648. X+         push    bp
  649. X+         push    ds
  650. X+         mov    ds,ovltblbse        ; ^ ovl tbl
  651. X+         xor    ax,ax            ; will contain the low word of lru
  652. X+         mov    dx,ax            ; will contain the high word of lru
  653. X+         mov    bp,ax            ; will contain ovl tbl entry
  654. X+         mov    bx,ax            ; ovl tbl ptr
  655. X+ ;         mov     cx,ovlcnt         ; number of ovl's to scan
  656. X+ ;foon:         test     ovlflg[bx],MASK loaded  ; is this one loaded?
  657. X+ ;         jz     skip             ; nope, try next one
  658. X+ ;         test     ovlflg[bx],MASK locked  ; is this one loacked?
  659. X+ ;         jnz     skip             ; yup, try next one
  660. X+ ;         test     ovlflg[bx],MASK running ; is this one running?
  661. X+ ;         jnz     skip             ; yup, try next one
  662. X+ ;         mov     si,WORD PTR ovltim     ; get global lru
  663. X+ ;         mov     di,WORD PTR ovltim+2
  664. X+ ;         sub     si,WORD PTR ovllrudat[bx] ; subtract from ovl lru
  665. X+ ;         sbb     di,WORD PTR ovllrudat[bx+2]
  666. X+ ;         cmp     dx,di             ; is this one older?
  667. X+ ;         jc     better          ; it sure is
  668. X+ ;         jnz     skip             ; it definitely isn't
  669. X+ ;         cmp     ax,si
  670. X+ ;         jnc     skip             ; it really isn't
  671. X+ ;better:     mov     ax,si             ; save the lru stuff and ovl ptr
  672. X+ ;         mov     dx,di
  673. X+ ;         mov     bp,bx
  674. X+ ;skip:         add     bx,ovlsegsiz         ; do next ovl
  675. X+ ;         loop     foon
  676. X+ ;         or     bp,bp             ; did we find anyone to kill?
  677. X+ ;         jnz     gotvictim         ; yes we did, partner.
  678. X+ ;         xor     bx,bx             ; Oh well, do it again disregarding the running flag
  679. X+         mov    cx,ovlcnt
  680. X+ foon1:        test    ovlflg[bx],MASK loaded
  681. X+         jz    skip1
  682. X+         test    ovlflg[bx],MASK locked
  683. X+         jnz    skip1
  684. X+         mov    si,WORD PTR ovltim
  685. X+         mov    di,WORD PTR ovltim+2
  686. X+         sub    si,WORD PTR ovllrudat[bx]
  687. X+         sbb    di,WORD PTR ovllrudat[bx+2]
  688. X+         cmp    dx,di
  689. X+         jc    better1
  690. X+         jnz    skip1
  691. X+         cmp    ax,si
  692. X+         jnc    skip1
  693. X+ better1:    mov    ax,si
  694. X+         mov    dx,di
  695. X+         mov    bp,bx
  696. X+ skip1:        add    bx,ovlsegsiz
  697. X+         loop    foon1
  698. X+         or    bp,bp            ; were we more successful this time?
  699. X+         jnz    gotvictim        ; now we got one.
  700. X+ nomoremem:
  701. X+         mov    al,5            ; were really %$# now!
  702. X+         mov    dx,offset nocore
  703. X+         jmp    putserr
  704. X+ gotvictim:
  705. X+         shr    bp,1            ; convert offset to segment
  706. X+         shr    bp,1
  707. X+         shr    bp,1
  708. X+         shr    bp,1
  709. X+         mov    ax,ds
  710. X+         add    ax,bp
  711. X+         pop    ds
  712. X+         pop    bp
  713. X+         pop    di
  714. X+         pop    si
  715. X+         pop    dx
  716. X+         pop    cx
  717. X+         pop    bx
  718. X+         ret
  719. X+ getvictim    endp
  720. X+ 
  721. X+ ;-------------------------------------------------------------------------------
  722. X+ 
  723. X+ setrunning    proc    near            ; set running flag on overlays still running
  724. X+ 
  725. X+         assume cs:code,ds:nothing,es:ovltbl
  726. X+ 
  727. X+         push    es
  728. X+         mov    es,ovltblbse
  729. X+         mov    cx,ovlcnt
  730. X+         xor    bx,bx
  731. X+ jim:        and    ovlflg[bx],NOT MASK running ; start by clearing them all
  732. X+         add    bx,ovlsegsiz
  733. X+         loop    jim
  734. X+ 
  735. X+         ; Now chain down the stack links, setting running flags
  736. X+ 
  737. X+         mov    bx,curovl
  738. X+         sub    bx,6
  739. X+         jmp    jam
  740. X+ jamloop:
  741. X+         mov    ds,cs:[bx]
  742. X+         assume    ds:ovltbl
  743. X+         or    ovlflg,MASK running
  744. X+         sub    bx,6
  745. X+ jam:
  746. X+         cmp    word ptr cs:[bx],-1    ; end of stack ?
  747. X+         jnz    jamloop
  748. X+         pop    es
  749. X+         ret
  750. X+ 
  751. X+ setrunning        endp
  752. X+ 
  753. X+ ;-------------------------------------------------------------------------------
  754. X+ 
  755. X+ int21        proc    near
  756. X+ 
  757. X+ ; free almost all overlay memory if app. tries to call the DOS exec function.
  758. X+ 
  759. X+         cmp    ah,DOSEXEC
  760. X+         jz    freeall
  761. X+         cmp    ah,TERMINATE
  762. X+         jz    saybyebye
  763. X+         jmp    cs:oldint21
  764. X+ saybyebye:
  765. X+         pop    ax            ; clean up stack
  766. X+         pop    ax
  767. X+         pop    ax
  768. X+         mov    al,0            ; return code 0
  769. X+         mov    dx,offset exitmsg
  770. X+         jmp    putserr
  771. X+ freeall:
  772. X+         push    ax
  773. X+         push    bx
  774. X+         push    cx
  775. X+         push    dx
  776. X+         push    si
  777. X+         push    di
  778. X+         push    bp
  779. X+         push    es
  780. X+         push    ds            ; preserve calling env.
  781. X+ 
  782. X+         assume cs:code,ds:nothing,es:ovltbl
  783. X+ 
  784. X+         mov    ax,cs:memblk1st     ; start de-allocating from first blk
  785. X+         jmp    short lastblk
  786. X+ unloadlp:
  787. X+         mov    ds,ax
  788. X+         cmp    ax,cs:ovltblbse     ; in alloced area ?
  789. X+         jc    nextmemblk
  790. X+         test    ds:memblkflg,MASK_used    ; mem blk used ?
  791. X+         jz    nextmemblk
  792. X+         mov    es,ds:memblkovl
  793. X+         and    ovlflg,NOT MASK loaded    ; flag overlay as unloaded
  794. X+ nextmemblk:
  795. X+         mov    ax,ds:memblknxt
  796. X+ lastblk:
  797. X+         or    ax,ax            ; keep going till no more
  798. X+         jnz    unloadlp
  799. X+ 
  800. X+         mov    ax,cs:ovltblbse
  801. X+         add    ax,cs:ovlcnt
  802. X+         mov    es,ax            ; ^ to first mem blk in alloced mem
  803. X+         mov    es:memblksiz,2        ; adjust size
  804. X+         mov    es:memblknxt,0        ; no other blocks after this one
  805. X+         mov    es:memblkflg,0        ; not used
  806. X+         mov    cs:memstat,0ffh     ; memory needs to be re-alloced some day
  807. X+ 
  808. X+         mov    dx,word ptr cs:oldint21
  809. X+         mov    ds,word ptr cs:oldint21+2
  810. X+         mov    ah,DOSSETVEC        ; put back DOS vector to avoid calling ourselves again!
  811. X+         mov    al,21h
  812. X+         int    DOS
  813. X+ 
  814. X+         mov    es,cs:ovltblbse
  815. X+         mov    bx,cs:ovlcnt
  816. X+         add    bx,2            ; re-adjust alloced size
  817. X+         mov    ah,DOSREALLOC
  818. X+         int    DOS
  819. X+         pop    ds
  820. X+         pop    es
  821. X+         pop    bp
  822. X+         pop    di
  823. X+         pop    si
  824. X+         pop    dx
  825. X+         pop    cx
  826. X+         pop    bx
  827. X+         pop    ax
  828. X+         jmp    cs:oldint21        ; allow DOS to continue!
  829. X+ 
  830. X+ int21        endp
  831. X+ 
  832. X+ ;-------------------------------------------------------------------------------
  833. X+ 
  834. X+ reallocmem    proc    near
  835. X+ 
  836. X+ ; re-allocate our memory after a DOS exec function
  837. X+ 
  838. X+         push    es
  839. X+         mov    ah,DOSREALLOC
  840. X+         mov    es,cs:ovltblbse     ; mem blk handle
  841. X+         mov    bx,0ffffh        ; find out how much there is
  842. X+         int    DOS
  843. X+         mov    ah,DOSREALLOC        ; re-allocate our own memory
  844. X+         mov    es,cs:ovltblbse
  845. X+         push    bx            ; contains largest available blk
  846. X+         int    DOS
  847. X+         mov    cs:memstat,0        ; flag it re-alloced
  848. X+         mov    ax,cs:ovltblbse
  849. X+         add    ax,cs:ovlcnt
  850. X+         mov    es,ax            ; ^ to first mem blk in alloced mem
  851. X+         pop    ax
  852. X+         sub    ax,cs:ovlcnt        ; remove ovl rbl size
  853. X+         mov    es:memblksiz,ax     ; fix mem blk size
  854. X+ 
  855. X+         mov    ah,DOSGETVEC
  856. X+         mov    al,21h
  857. X+         int    DOS            ; get original vector
  858. X+         mov    word ptr cs:oldint21,bx ; save original vector
  859. X+         mov    word ptr cs:oldint21+2,es
  860. X+ 
  861. X+         mov    ah,DOSSETVEC
  862. X+         mov    al,21h
  863. X+         mov    bx,cs
  864. X+         mov    ds,bx
  865. X+         mov    dx,OFFSET int21     ; point to int21
  866. X+         int    DOS            ; set vector
  867. X+ 
  868. X+         pop    es
  869. X+         ret
  870. X+ 
  871. X+ reallocmem    endp
  872. X+ 
  873. X+ ;-------------------------------------------------------------------------------
  874. X+ 
  875. X+ releasepages    proc    near            ; Arg in es, result in ax
  876. X+ 
  877. X+ ; release any memory (and overlays) where this overlay should reside
  878. X+ 
  879. X+         assume    es:ovltbl
  880. X+ 
  881. X+         mov    bx,es:ovlmemblk     ; start of memory to release
  882. X+ doitagain:
  883. X+         mov    ax,memblk1st        ; first memory blk
  884. X+         jmp    dvart
  885. X+ dvartloop:
  886. X+         mov    ds,ax            ; memory blk to check
  887. X+         cmp    bx,ax            ; does it start below the memory to release?
  888. X+         jnc    dvartsmaller        ; yup
  889. X+         mov    dx,bx
  890. X+         add    dx,es:ovlsiz
  891. X+         add    dx,memctlblksiz / PARSIZ; end of memory to release
  892. X+         cmp    ax,dx            ; does it start above?
  893. X+         jnc    dvartsilly        ; yup
  894. X+         call    killmem         ; it's in the way. Zap it.
  895. X+         jmp    chkmemblk
  896. X+ dvartsmaller:
  897. X+         add    ax,ds:memblksiz     ; end of this memory blk
  898. X+         cmp    bx,ax            ; does it end below the memory to release?
  899. X+         jnc    dvartsilly        ; yup
  900. X+         call    killmem         ; Oh well, zap it too.
  901. X+ chkmemblk:                    ; was that enough?
  902. X+         mov    ax,ds            ; recently freed memory blk
  903. X+         cmp    bx,ax            ; does it start in the memory to be released?
  904. X+         jc    dvartsilly        ; yup, wasn't enough
  905. X+         mov    dx,bx
  906. X+         add    dx,es:ovlsiz
  907. X+         add    dx,memctlblksiz / PARSIZ; end of memory to be released
  908. X+         add    ax,ds:memblksiz     ; end of freed memory
  909. X+         cmp    ax,dx            ; does it end in the memory to be released?
  910. X+         jc    dvartsilly        ; yup, release more
  911. X+ dvartgotblk:
  912. X+         mov    ax,ds            ; this is it!
  913. X+         mov    cx,bx
  914. X+         sub    cx,ax            ; # of paragraphs between start of memory to release and mem blk
  915. X+         jz    nosplit
  916. X+         call    splitblkhigh        ; split the block
  917. X+ nosplit:
  918. X+         mov    cx,es:ovlsiz
  919. X+         add    cx,memctlblksiz / PARSIZ; paragraphs needed to load ovl
  920. X+         jmp    splitblklow        ; split remaining block
  921. X+ dvartsilly:
  922. X+         mov    ax,ds:memblknxt
  923. X+ dvart:
  924. X+         or    ax,ax            ; enf of mem list?
  925. X+         jz    dvartnocore
  926. X+         jmp    dvartloop        ; play it again Sam.
  927. X+ dvartnocore:
  928. X+         mov    al,5            ; super OOPS!
  929. X+         mov    dx,offset nocore
  930. X+         jmp    putserr
  931. X+ 
  932. X+ releasepages    endp
  933. X+ 
  934. X+ ;-------------------------------------------------------------------------------
  935. X+ 
  936. X+ getpages    proc    near            ; get enough memory to load ovl
  937. X+ 
  938. X+         mov    cx,ax
  939. X+         add    cx,memctlblksiz / PARSIZ; total paragraphs needed
  940. X+         call    largestmem        ; find largest free blk
  941. X+         cmp    dx,cx            ; large enough?
  942. X+         jnc    gotdork         ; yup.
  943. X+ dorkkill:
  944. X+         call    getvictim        ; select a victim to release
  945. X+         call    killovl         ; kill the selected victim
  946. X+         cmp    ds:memblksiz,cx     ; was it enough?
  947. X+         jc    dorkkill        ; nope, select another one
  948. X+ gotdork:
  949. X+         jmp    splitblklow        ; split the free blk
  950. X+ 
  951. X+ getpages    endp
  952. X+ 
  953. X+ ;-------------------------------------------------------------------------------
  954. X+ 
  955. X+ splitblklow    proc    near
  956. X+ 
  957. X+ ; split a block of memory returning the lower one to be used.
  958. X+ 
  959. X+         push    es
  960. X+         or    ds:memblkflg,MASK_used    ; set low block used
  961. X+         mov    ax,ds
  962. X+         add    ax,cx
  963. X+         mov    es,ax            ; ^ to upper blk to be created
  964. X+         mov    ax,ds:memblksiz
  965. X+         sub    ax,cx
  966. X+         cmp    ax,1            ; must be at least 1 para remaining to split
  967. X+         jc    noodorksplit        ; don't split
  968. X+         mov    ds:memblksiz,cx     ; fix blk sizes
  969. X+         mov    es:memblksiz,ax
  970. X+         mov    ax,ds:memblknxt     ; fix pointers
  971. X+         mov    es:memblknxt,ax
  972. X+         mov    ds:memblknxt,es
  973. X+         mov    es:memblkprv,ds
  974. X+         mov    es:memblkflg,0        ; set upper to not used
  975. X+         push    ds
  976. X+         mov    ax,es:memblknxt
  977. X+         or    ax,ax
  978. X+         jz    domergelow
  979. X+         mov    ds,ax            ; fix blk after upper to point to upper
  980. X+         mov    ds:memblkprv,es
  981. X+ domergelow:
  982. X+         mov    ax,es
  983. X+         mov    ds,ax
  984. X+         call    mergemem        ; merge remaining free memory
  985. X+         pop    ds
  986. X+ noodorksplit:
  987. X+         pop    es
  988. X+         mov    ds:memblkovl,es     ; fix ptr to ovl
  989. X+         mov    ax,ds            ; return lower blk segment
  990. X+         ret
  991. X+ 
  992. X+ splitblklow    endp
  993. X+ 
  994. X+ ;-------------------------------------------------------------------------------
  995. X+ 
  996. X+ splitblkhigh    proc    near
  997. X+ 
  998. X+ ; split a block of memory returning the upper one to be used.
  999. X+ 
  1000. X+         push    es
  1001. X+         mov    ax,ds
  1002. X+         add    ax,cx
  1003. X+         mov    es,ax            ; ^ to upper blk to be created
  1004. X+         mov    ax,ds:memblksiz
  1005. X+         sub    ax,cx            ; # of para remaining in upper blk
  1006. X+         mov    ds:memblksiz,cx     ; fix blk sizes
  1007. X+         mov    es:memblksiz,ax
  1008. X+         mov    ax,ds:memblknxt     ; fix blk pointers
  1009. X+         mov    es:memblknxt,ax
  1010. X+         mov    ds:memblknxt,es
  1011. X+         mov    es:memblkprv,ds
  1012. X+         mov    ds:memblkflg,0        ; set lower to not used
  1013. X+         or    es:memblkflg,MASK_used    ; set upper to used
  1014. X+         mov    ax,es:memblknxt
  1015. X+         or    ax,ax
  1016. X+         jz    domergehigh
  1017. X+         push    ds            ; fix blk after upper to point to upper
  1018. X+         mov    ds,ax
  1019. X+         mov    ds:memblkprv,es
  1020. X+         pop    ds
  1021. X+ domergehigh:
  1022. X+         call    mergemem        ; merge remaining free memory
  1023. X+ nodorksplit:
  1024. X+         mov    ax,es
  1025. X+         mov    ds,ax
  1026. X+         pop    es
  1027. X+         mov    ds:memblkovl,es     ; fix ovl ptr
  1028. X+         mov    ax,ds            ; return upper blk segment
  1029. X+         ret
  1030. X+ 
  1031. X+ splitblkhigh    endp
  1032. X+ 
  1033. X+ ;-------------------------------------------------------------------------------
  1034. X+ 
  1035. X+ largestmem    proc    near    ; returns seg in ax, size in dx; clobbers bx,ds,es
  1036. X+                 ; retruns first block that's large enough if possible
  1037. X+ 
  1038. X+         mov    ax,memblk1st        ; first mem blk
  1039. X+         xor    dx,dx            ; largest size found
  1040. X+         jmp    gook
  1041. X+ gookloop:    mov    ds,ax
  1042. X+         test    ds:memblkflg,MASK_used    ; is this blk used?
  1043. X+         jnz    gookme            ; yup
  1044. X+         cmp    ds:memblksiz,cx     ; is it large enough?
  1045. X+         jc    gookme            ; nope
  1046. X+         mov    dx,ds:memblksiz     ; got one!
  1047. X+         ret
  1048. X+ gookme:
  1049. X+         mov    ax,ds:memblknxt
  1050. X+ gook:        or    ax,ax            ; end of list?
  1051. X+         jnz    gookloop        ; around and around
  1052. X+         ret
  1053. X+ 
  1054. X+ largestmem    endp
  1055. X+ 
  1056. X+ ;-------------------------------------------------------------------------------
  1057. X+ 
  1058. X+ killmem     proc    near
  1059. X+ 
  1060. X+         test    ds:memblkflg,MASK_used    ; is it used?
  1061. X+         jz    memnotused        ; don't kill ovl
  1062. X+         push    es
  1063. X+         mov    es,ds:memblkovl
  1064. X+         and    es:ovlflg,NOT MASK loaded ; zap ovl associated with this blk
  1065. X+         pop    es
  1066. X+ memnotused:
  1067. X+         jmp    mergemem        ; merge free memory
  1068. X+ 
  1069. X+ killmem     endp
  1070. X+ 
  1071. X+ ;-------------------------------------------------------------------------------
  1072. X+ 
  1073. X+ killovl     proc    near        ; preserves bx
  1074. X+ 
  1075. X+         mov    ds,ax
  1076. X+         assume    ds:ovltbl
  1077. X+         and    ovlflg,NOT MASK loaded    ; ovl no longer loaded
  1078. X+         mov    ax,ovlmemblk        ; get mem blk
  1079. X+         mov    ds,ax
  1080. X+         jmp    mergemem        ; merge free memory
  1081. X+ 
  1082. X+ killovl     endp
  1083. X+ 
  1084. X+ ;-------------------------------------------------------------------------------
  1085. X+ 
  1086. X+ mergemem    proc    near
  1087. X+ 
  1088. X+ ; merge physically adjacent free memory blocks. Preserves es. ds -> a free block.
  1089. X+ 
  1090. X+         push    es
  1091. X+         and    ds:memblkflg,NOT MASK_used ; set current free
  1092. X+         mov    ax,ds:memblkprv     ; get previous blk
  1093. X+         or    ax,ax            ; was there a previous blk?
  1094. X+         jz    gibber            ; nope
  1095. X+         mov    es,ax
  1096. X+         test    es:memblkflg,MASK_used    ; is the previous blk used?
  1097. X+         jnz    gibber            ; yup
  1098. X+         add    ax,es:memblksiz     ; end of previous blk
  1099. X+         mov    dx,ds
  1100. X+         cmp    dx,ax            ; physically adjacent?
  1101. X+         jnz    gibber            ; nope
  1102. X+         mov    ax,ds:memblksiz
  1103. X+         add    es:memblksiz,ax     ; adjust size of new larger blk
  1104. X+         mov    ax,ds:memblknxt     ; fix pointers
  1105. X+         mov    es:memblknxt,ax
  1106. X+         or    ax,ax
  1107. X+         jz    almostgibber
  1108. X+         mov    ds,ax            ; fix pointer of next blk
  1109. X+         mov    ds:memblkprv,es
  1110. X+ almostgibber:
  1111. X+         mov    ax,es
  1112. X+         mov    ds,ax            ; new blk segment
  1113. X+ gibber:
  1114. X+         mov    ax,ds:memblknxt     ; get next blk
  1115. X+         or    ax,ax            ; was there a next blk?
  1116. X+         jz    killdone        ; nope
  1117. X+         mov    es,ax
  1118. X+         test    es:memblkflg,MASK_used    ; is the nxt blk used?
  1119. X+         jnz    killdone        ; yup
  1120. X+         mov    ax,ds
  1121. X+         add    ax,ds:memblksiz     ; end of this blk
  1122. X+         mov    dx,es
  1123. X+         cmp    ax,dx            ; physically adjacent?
  1124. X+         jnz    killdone        ; nope
  1125. X+         mov    ax,es:memblksiz
  1126. X+         add    ds:memblksiz,ax     ; adjust size of new larger blk
  1127. X+         mov    ax,es:memblknxt     ; fix pointers
  1128. X+         mov    ds:memblknxt,ax
  1129. X+         or    ax,ax
  1130. X+         jz    killdone
  1131. X+         mov    es,ax            ; fix pointer of blk after nxt
  1132. X+         mov    es:memblkprv,ds
  1133. X+ killdone:
  1134. X+         and    ds:memblkflg,NOT MASK_used ; make sure it's free
  1135. X+         pop    es
  1136. X+         ret
  1137. X+ 
  1138. X+ mergemem    endp
  1139. X+ 
  1140. X+ ;-------------------------------------------------------------------------------
  1141. X+ 
  1142. X+ gethdr        proc    near            ; read EXE header from handle
  1143. X+ 
  1144. X+         push    cx
  1145. X+         mov    ax,cs
  1146. X+         mov    ds,ax
  1147. X+         mov    dx,offset hdr        ; a place to put it
  1148. X+         mov    bx,ovlexefilhdl     ; the file handle
  1149. X+         mov    cx,hdrsize        ; header size in bytes
  1150. X+         mov    ah,DOSREAD
  1151. X+         int    DOS            ; read from file
  1152. X+         jc    exegone         ; oops
  1153. X+         cmp    ax,cx            ; got correct number of bytes?
  1154. X+         jnz    exegone         ; nope
  1155. X+         pop    cx
  1156. X+         ret                ; Wow, it worked!
  1157. X+ exegone:
  1158. X+         mov    al,5            ; You lose!
  1159. X+         mov    dx,offset nofile
  1160. X+         jmp    putserr
  1161. X+ 
  1162. X+ gethdr        endp
  1163. X+ 
  1164. X+ ;-------------------------------------------------------------------------------
  1165. X+ 
  1166. X+ putserr     proc    near
  1167. X+ 
  1168. X+ ; display error msg, close file, restore int vectors, free mem and return to DOS.
  1169. X+ 
  1170. X+         push    ax            ; keep return code for later
  1171. X+         mov    ax,cs
  1172. X+         mov    ds,ax
  1173. X+         mov    ah,PRINT
  1174. X+         int    DOS            ; display error msg
  1175. X+         mov    dx,word ptr oldvec    ; get old vector
  1176. X+         cmp    dx,-1            ; was it ever replaced?
  1177. X+         jz    free21            ; nope
  1178. X+         push    ds
  1179. X+         mov    ds,word ptr oldvec+2
  1180. X+         mov    ah,DOSSETVEC        ; put it back then.
  1181. X+         mov    al,$$INTNO
  1182. X+         int    DOS
  1183. X+         pop    ds
  1184. X+ free21:
  1185. X+         mov    dx,word ptr oldint21
  1186. X+         cmp    dx,-1
  1187. X+         jz    freemem
  1188. X+         push    ds
  1189. X+         mov    ds,word ptr oldint21+2
  1190. X+         mov    ah,DOSSETVEC        ; put it back then.
  1191. X+         mov    al,21h
  1192. X+         int    DOS
  1193. X+         pop    ds
  1194. X+ freemem:
  1195. X+         mov    ax,ovltblbse        ; get memory blk segment
  1196. X+         cmp    ax,-1            ; was one ever allocated?
  1197. X+         jz    closefile        ; nope
  1198. X+         mov    es,ax
  1199. X+         mov    ah,DOSFREE        ; must free it.
  1200. X+         int    DOS
  1201. X+ closefile:
  1202. X+         mov    bx,ovlexefilhdl     ; get file handle
  1203. X+         cmp    bx,-1            ; was the file ever opened?
  1204. X+         jz    byebye            ; nope
  1205. X+         mov    ah,DOSCLOSE        ; close it
  1206. X+         int    DOS
  1207. X+ byebye:
  1208. X+         pop    ax            ; return code in al
  1209. X+         mov    ah,TERMINATE
  1210. X+         int    DOS            ; terminate this process
  1211. X+ 
  1212. X+ putserr     endp
  1213. X+ 
  1214. X+ code        ends
  1215. X+ 
  1216. X+         end
  1217. X*** /dev/null    Sun Nov 19 14:15:44 1989
  1218. X--- others/ovlmgr.doc    Tue Nov 14 21:11:07 1989
  1219. X***************
  1220. X*** 0 ****
  1221. X--- 1,200 ----
  1222. X+              Brief notes about ovlmgr.asm
  1223. X+              ----------------------------
  1224. X+              (revised 1989nov12)
  1225. X+ 
  1226. X+ OVLMGR.ASM is a preliminary version of a multiple-residency overlay
  1227. X+ manager for use with the Microsoft Overlay Linker. It is functionally
  1228. X+ compatible with the one in the MSC library _except_:
  1229. X+ 
  1230. X+ - it doesn't support setjmp()/longjmp().
  1231. X+ - it leaves only a SMALL, fixed space for your heap (1).
  1232. X+ - it usually accesses the disk less often and is a lot faster in some
  1233. X+   applications.
  1234. X+ - it has different tuning characteristics.
  1235. X+ - you must (of course) link OVLMGR.OBJ into the root overlay (that is,
  1236. X+   outside any parentheses in the link command).
  1237. X+ 
  1238. X+   See also the bugs list below.
  1239. X+ 
  1240. X+ As with other Microsoft-compatible overlay handlers you must be *very*
  1241. X+ careful never to call a function in an overlay through a pointer,
  1242. X+ unless the initiator of the call resides in the *same* physical
  1243. X+ overlay as the target (2).
  1244. X+ 
  1245. X+ Although using the overlay manager is in essence much like using
  1246. X+ Microsoft's, they operate on a slightly different principle, and tuning
  1247. X+ for them is rather different. Technical part begins.
  1248. X+ 
  1249. X+ When overlay linking is requested (see you linker manual), the MS
  1250. X+ overlay linker changes all far calls into overlays from the (normal,
  1251. X+ 8086) format:
  1252. X+ 
  1253. X+     offset    contents
  1254. X+     ------    --------
  1255. X+     :0000    CALL
  1256. X+     :0001    target-offset
  1257. X+     :0003    target-segment
  1258. X+ 
  1259. X+ to this:
  1260. X+     :0000    INT
  1261. X+     :0001    int#    target-mod#
  1262. X+     :0003    target-offset
  1263. X+ 
  1264. X+ (note that here we are looking at the actual layout of the machine
  1265. X+ code, not at the assembly code as such) and relocates the code parts
  1266. X+ of all the different overlays into the *same* physical area. The
  1267. X+ overlaid code is all actually placed at the end of the .EXE file,
  1268. X+ after the 'normal' executable image, along with all its administrative
  1269. X+ data (fixups etc.).
  1270. X+     When this altered 'call' is executed, of course, the interrupt
  1271. X+ handler int# is invoked. Its job is to ensure that the target overlay
  1272. X+ module is in memory (reading it from the tail of the .EXE file if it
  1273. X+ isn't already loaded) and then transfer to the given offset within it,
  1274. X+ 'faking up' the effect of the 'real' far call that would normally have
  1275. X+ occurred.  Something similar must be done when the call returns, to
  1276. X+ ensure that the thing being returned *into* is still (or is once more)
  1277. X+ loaded.
  1278. X+     The Microsoft linker, as we have said, relocates all the
  1279. X+ overlays to the same load address; and, in fact, it allocates am empty
  1280. X+ block of memory there that is at least as large as the largest
  1281. X+ overlay. Into this area all the overlays are loaded without further
  1282. X+ change; thus, there can only ever be one overlay in memory at one
  1283. X+ time. Transferring from one overlay to another causes one overlay to
  1284. X+ replace the other in the allocated overlay swap area.
  1285. X+     Our overlay manager does not use the space allocated by the
  1286. X+ linker in the same way. Rather, it allocates almost all of the memory
  1287. X+ available from MS-DOS (including the original overlay area). As
  1288. X+ overlays are needed, they are loaded wherever they will fit, and
  1289. X+ dynamically relocated to that address.    Thus, many more than one
  1290. X+ overlay may be loaded at any given time, greatly increasing potential
  1291. X+ performance. Managament of space is more or less according to an LRU
  1292. X+ policy - once all of memory is full, the least recently used overlay
  1293. X+ is selected as the most likely candidate for replacement.
  1294. X+ 
  1295. X+ The implications of this difference are as follows: while with the
  1296. X+ conventional (default) overlay manager, the best strategy is to group
  1297. X+ object modules together in an overlay whenever they are known to be
  1298. X+ used in rapid succession, to make each overlay as big as possible (all
  1299. X+ things being equal) in order to take advantage of all available
  1300. X+ memory, and to make as few overlays as possible (to reduce the amount
  1301. X+ of disk access), the best strategy with our overaly manager is almost
  1302. X+ the reverse. Having a lot of small overlays will increase the amount
  1303. X+ of useful stuff that can be resident in memory at the same time; all
  1304. X+ of memory will automatically be employed; and there is no advantage at
  1305. X+ all to uniformity of size (except perhaps in the unlikely case of
  1306. X+ *exact* uniformity!).
  1307. X+     One thing that is no longer a problem with this version
  1308. X+ (though it was with all earlier versions of this overlay manager) is
  1309. X+ that the DOS exec() call works normally. The memory that is allocated
  1310. X+ for administering the overlay system is freed before the exec call is
  1311. X+ made and reallocated afterwards (we trap the DOS function request
  1312. X+ vector to do this, which isn't very nice as a programming practise but
  1313. X+ makes the existence of the overlay manager far more transparent).
  1314. X+ There is, however, one circumstance under which this can be
  1315. X+ problematic: if you use the exec() call to load a TSR application,
  1316. X+ thereby causing memory that the overlay manager was using to become
  1317. X+ unavailable, you may make it impossible for the overlaid application
  1318. X+ to proceed. This is because code that is nominally 'running' (i.e. is
  1319. X+ currently on the stack) cannot be relocated and must be reloaded
  1320. X+ at the *same address* that previously held it. If another process now
  1321. X+ owns that area of memory, there is nothing we can do.
  1322. X+     We believe that this should not be a serious concern in normal
  1323. X+ use.
  1324. X+ 
  1325. X+ NOTA BENE: This is a preliminary version of the overlay manager, but
  1326. X+ by now it should be fairly well debugged. If you are considering
  1327. X+ upgrading it please be aware that the following improvements are
  1328. X+ planned for the next version (though who knows when delivery will
  1329. X+ occur):
  1330. X+     Twice the speed
  1331. X+     EMS support
  1332. X+     compatible versions of setjmp() and longjmp()
  1333. X+     Integration with malloc() so the heap can grow
  1334. X+     Major code revamping
  1335. X+ 
  1336. X+ Enjoy!
  1337. X+ ------------------------------------------------------------------------
  1338. X+ MESSAGES
  1339. X+ 
  1340. X+ Not enough memory to run this program. Time to go to the store.
  1341. X+     Although DOS successfully loaded the programme, it proved
  1342. X+     impossible to allocate enough additional contiguous memory to
  1343. X+     load one or more of the overlays. Either reduce the
  1344. X+     RAM-loading of the application by reducing the size of either
  1345. X+     the root or the largest overlays, or increase the amount of
  1346. X+     memory available by unloading TSRs and/or simplifying your
  1347. X+     CONFIG.SYS.
  1348. X+ 
  1349. X+ Your dog eats all your remaining memory! You die.
  1350. X+     Either an internal error has occurred in ovlmgr or the
  1351. X+     application programme, or some event has caused memory that
  1352. X+     ovlmgr believed it could count on becoming unavailable. A
  1353. X+     typical example of the latter would be the result of
  1354. X+     attempting to load a TSR while an overlaid application is
  1355. X+     running.
  1356. X+ 
  1357. X+ The Nymph stole your .EXE file! You die.
  1358. X+     For some reason ovlmgr could not locate or read the original
  1359. X+     .EXE file in which the overlays reside. This could be due to
  1360. X+     your attempting to use a very old version of DOS,
  1361. X+     an abject shortage of file handles, some strange event causng
  1362. X+     the file to be deleted, a disk error, or the diskette that
  1363. X+     contained the executable has been removed.
  1364. X+ ------------------------------------------------------------------------
  1365. X+ KNOWN BUGS
  1366. X+ 
  1367. X+ The present version cannot always be used as a direct replacement for
  1368. X+ Microsoft's overlay manager (even granted the documented differences)
  1369. X+ because the minimum size required for an overlaid programme to run is
  1370. X+ at least the size of the root plus TWICE the size of the largest
  1371. X+ overlay. If a programme has previously had its overlay structure tuned
  1372. X+ to take best advantage of Microsoft overlays, this may well cause a
  1373. X+ problem. The overlays themselves will need to be split up.
  1374. X+ 
  1375. X+ The error messages are whimsical and NetHack-culture-specific.
  1376. X+ Somewhat more informative versions appeared in one version of the
  1377. X+ programme but they seem to have been lost.
  1378. X+ 
  1379. X+ Transfers between overlays are very slow in machine terms, even if
  1380. X+ both overlays happen to reside in memory at the time.
  1381. X+ 
  1382. X+ Locking overlays into memory is not really implemeted even though
  1383. X+ reading the source code might make you think it was.
  1384. X+ ------------------------------------------------------------------------
  1385. X+ BUG ALERT
  1386. X+ 
  1387. X+ To repeat a point made above, if you ever try to call a function in an
  1388. X+ overlay through a pointer, you *may* die with the Microsoft overlay
  1389. X+ manager. If you ever try to call a function in an overlay through a
  1390. X+ pointer, you *will* die with ours. Nothing in an overlay ever ends up
  1391. X+ in the same segment as the linker anticipated.    You have been warned!
  1392. X+ ------------------------------------------------------------------------
  1393. X+ FOOTNOTES
  1394. X+ 
  1395. X+ (1) If you hunt through the code you will find a magic constant you
  1396. X+ can play with to vary this allotment, if you're brave enough. It's
  1397. X+ currently tuned for NetHack 3.0. If you should get a message to the
  1398. X+ effect that NetHack can't allocate 28000 and some bytes when entering
  1399. X+ a maze level, that isn't our problem! In all probability you forgot to
  1400. X+ rebuild your special level files when you changed the compiler flags.
  1401. X+ We got that one, too, at one point.
  1402. X+ 
  1403. X+ (2) This problem can be circumvented through the use of surrogate
  1404. X+ 'trampoline' functions: functions that reside in the root overlay and
  1405. X+ simply pass right through to the 'real', overlaid, implementations.
  1406. X+ This can even be made transparent to the source code through the use
  1407. X+ of the C macro preprocessor, with a locution of the form
  1408. X+     #define foo(x) foo_(x)
  1409. X+ visible everywhere except at the actual definition point of the
  1410. X+ trampoline. This has been implemented in Nethack 3.0h.
  1411. X+ ----------------------------------------------------------------------
  1412. X+ NOTICE
  1413. X+ 
  1414. X+ OVLMGR.ASM is brought to you by Pierre Martineau and Stephen Spackman.
  1415. X+ It, and this document, are copyright. They are, however, provided as
  1416. X+ part of NetHack and may be freely distributed as described in the
  1417. X+ NetHack license.
  1418. X+ ----------------------------------------------------------------------
  1419. X+ Stephen P Spackman               stephen@concour.cs.concordia.ca
  1420. X+ ----------------------------------------------------------------------
  1421. X+      Copyright (C) 1989 Pierre G Martineau and Stephen P Spackman
  1422. X*** others/Old/pcmain.c    Sun Nov 19 14:16:14 1989
  1423. X--- others/pcmain.c    Tue Nov 14 20:32:13 1989
  1424. X***************
  1425. X*** 1,4 ****
  1426. X! /*    SCCS Id: @(#)pcmain.c    3.0    88/11/23
  1427. X  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  1428. X  /* NetHack may be freely redistributed.  See license for details. */
  1429. X  /* main.c - PC, ST, and Amiga NetHack */
  1430. X--- 1,4 ----
  1431. X! /*    SCCS Id: @(#)pcmain.c    3.0    89/10/25
  1432. X  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  1433. X  /* NetHack may be freely redistributed.  See license for details. */
  1434. X  /* main.c - PC, ST, and Amiga NetHack */
  1435. X***************
  1436. X*** 8,13 ****
  1437. X--- 8,14 ----
  1438. X  #ifndef NO_SIGNAL
  1439. X  #include <signal.h>
  1440. X  #endif
  1441. X+ #include <ctype.h>
  1442. X  #ifdef MACOS
  1443. X  extern WindowPtr    HackWindow;
  1444. X  extern short *switches;
  1445. X***************
  1446. X*** 21,27 ****
  1447. X  char SAVEF[FILENAME];
  1448. X  
  1449. X  char *hname = "NetHack";    /* used for syntax messages */
  1450. X! #ifndef AMIGA
  1451. X  char obuf[BUFSIZ];    /* BUFSIZ is defined in stdio.h */
  1452. X  #endif
  1453. X  int hackpid;        /* not used anymore, but kept in for save files */
  1454. X--- 22,28 ----
  1455. X  char SAVEF[FILENAME];
  1456. X  
  1457. X  char *hname = "NetHack";    /* used for syntax messages */
  1458. X! #if !defined(AMIGA) && !defined(MACOS)
  1459. X  char obuf[BUFSIZ];    /* BUFSIZ is defined in stdio.h */
  1460. X  #endif
  1461. X  int hackpid;        /* not used anymore, but kept in for save files */
  1462. X***************
  1463. X*** 57,62 ****
  1464. X--- 58,65 ----
  1465. X  # endif
  1466. X  #endif
  1467. X  
  1468. X+ static const char *classes = "ABCEHKPRSTVW";
  1469. X+ 
  1470. X  int
  1471. X  main(argc,argv)
  1472. X  int argc;
  1473. X***************
  1474. X*** 160,166 ****
  1475. X  # endif /* DGK && !OLD_TOS */
  1476. X  
  1477. X      initoptions();
  1478. X! # ifdef TOS
  1479. X      if (flags.IBMBIOS && flags.use_color)
  1480. X          set_colors();
  1481. X  # endif
  1482. X--- 163,169 ----
  1483. X  # endif /* DGK && !OLD_TOS */
  1484. X  
  1485. X      initoptions();
  1486. X! # if defined(TOS) && defined(TEXTCOLOR)
  1487. X      if (flags.IBMBIOS && flags.use_color)
  1488. X          set_colors();
  1489. X  # endif
  1490. X***************
  1491. X*** 236,242 ****
  1492. X          case 'D':
  1493. X  # ifdef WIZARD
  1494. X              /* Must have "name" set correctly by NETHACK.CNF,
  1495. X!              * NETHACKOPTIONS, or -U
  1496. X               * before this flag to enter wizard mode. */
  1497. X              if(!strcmp(plname, WIZARD)) {
  1498. X                  wizard = TRUE;
  1499. X--- 239,245 ----
  1500. X          case 'D':
  1501. X  # ifdef WIZARD
  1502. X              /* Must have "name" set correctly by NETHACK.CNF,
  1503. X!              * NETHACKOPTIONS, or -u
  1504. X               * before this flag to enter wizard mode. */
  1505. X              if(!strcmp(plname, WIZARD)) {
  1506. X                  wizard = TRUE;
  1507. X***************
  1508. X*** 263,269 ****
  1509. X                argv++;
  1510. X                (void) strncpy(plname, argv[0], sizeof(plname)-1);
  1511. X              } else
  1512. X!                 Printf("Player name expected after -U\n");
  1513. X              break;
  1514. X  #ifdef DGK
  1515. X          /* Player doesn't want to use a RAM disk
  1516. X--- 266,272 ----
  1517. X                argv++;
  1518. X                (void) strncpy(plname, argv[0], sizeof(plname)-1);
  1519. X              } else
  1520. X!                 Printf("Player name expected after -u\n");
  1521. X              break;
  1522. X  #ifdef DGK
  1523. X          /* Player doesn't want to use a RAM disk
  1524. X***************
  1525. X*** 273,281 ****
  1526. X              break;
  1527. X  #endif
  1528. X          default:
  1529. X!             /* allow -T for Tourist, etc. */
  1530. X!             (void) strncpy(pl_character, argv[0]+1,
  1531. X!                 sizeof(pl_character)-1);
  1532. X          }
  1533. X      }
  1534. X  
  1535. X--- 276,302 ----
  1536. X              break;
  1537. X  #endif
  1538. X          default:
  1539. X!             if (index(classes, toupper(argv[0][1]))) {
  1540. X!                 /* allow -T for Tourist, etc. */
  1541. X!                 (void) strncpy(pl_character, argv[0]+1,
  1542. X!                            sizeof(pl_character)-1);
  1543. X!                 break;
  1544. X!             } else Printf("\nUnknown switch: %s\n", argv[0]);
  1545. X!         case '?':
  1546. X! Printf("\nUsage: %s [-d dir] -s [-[%s]] [maxrank] [name]...", hname, classes);
  1547. X! Printf("\n       or");
  1548. X! Printf("\n       %s [-d dir] [-u name] [-[%s]]", hname, classes);
  1549. X! #if defined(WIZARD) || defined(EXPLORE_MODE)
  1550. X!             Printf(" [-[DX]]");
  1551. X! #endif
  1552. X! #ifdef NEWS
  1553. X!             Printf(" [-n]");
  1554. X! #endif
  1555. X! #ifdef DGK
  1556. X!             Printf(" [-r]");
  1557. X! #endif
  1558. X!             putchar('\n');
  1559. X!             return 0;
  1560. X          }
  1561. X      }
  1562. X  
  1563. X***************
  1564. X*** 288,300 ****
  1565. X          Strcpy(plname, "wizard");
  1566. X      else
  1567. X  #endif
  1568. X- #if defined(KR1ED) && defined(WIZARD) && defined(MACOS)
  1569. X-     if (!strcmp(plname,WIZARD))
  1570. X-         Strcpy(plname, "wizard");
  1571. X-     else
  1572. X- #endif
  1573. X      if (!*plname)
  1574. X          askname();
  1575. X      plnamesuffix();        /* strip suffix from name; calls askname() */
  1576. X                  /* again if suffix was whole name */
  1577. X                  /* accepts any suffix */
  1578. X--- 309,326 ----
  1579. X          Strcpy(plname, "wizard");
  1580. X      else
  1581. X  #endif
  1582. X      if (!*plname)
  1583. X          askname();
  1584. X+ #if defined(WIZARD) && defined(MACOS)
  1585. X+ # ifdef KR1ED
  1586. X+     if (!strcmp(plname,WIZARD_NAME)) {
  1587. X+ # else
  1588. X+     if (!strcmp(plname,WIZARD)) {
  1589. X+ # endif
  1590. X+         Strcpy(plname, "wizard");
  1591. X+         wizard = true;
  1592. X+     }
  1593. X+ #endif
  1594. X      plnamesuffix();        /* strip suffix from name; calls askname() */
  1595. X                  /* again if suffix was whole name */
  1596. X                  /* accepts any suffix */
  1597. X***************
  1598. X*** 431,437 ****
  1599. X  }
  1600. X  
  1601. X  /*
  1602. X!  * plname is filled either by an option (-U Player  or  -UPlayer) or
  1603. X   * explicitly (by being the wizard) or by askname.
  1604. X   * It may still contain a suffix denoting pl_character.
  1605. X   */
  1606. X--- 457,463 ----
  1607. X  }
  1608. X  
  1609. X  /*
  1610. X!  * plname is filled either by an option (-u Player  or  -uPlayer) or
  1611. X   * explicitly (by being the wizard) or by askname.
  1612. X   * It may still contain a suffix denoting pl_character.
  1613. X   */
  1614. X*** /dev/null    Sun Nov 19 14:17:50 1989
  1615. X--- others/trampoli.c    Fri Nov 17 20:45:08 1989
  1616. X***************
  1617. X*** 0 ****
  1618. X--- 1,420 ----
  1619. X+ /*    SCCS Id: @(#)trampoli.c     3.0    89/11/15      */
  1620. X+ /* Copyright (c) 1989, by Norm Meluch and Stephen Spackman      */
  1621. X+ /* NetHack may be freely redistributed.  See license for details. */
  1622. X+ 
  1623. X+ #include "hack.h"
  1624. X+ 
  1625. X+ /****************************************************************************/
  1626. X+ /*                                        */
  1627. X+ /*    This file contains a series of declarations of "one liner"        */
  1628. X+ /*    functions.  These functions are to avoid calls to functions via     */
  1629. X+ /*    pointers.  This is necessary when the function called is in an      */
  1630. X+ /*    overlay segment.                            */
  1631. X+ /*    The original function (eg foo) has been defined to be foo_ and        */
  1632. X+ /*    now the declaration of foo is placed in this file calling foo        */
  1633. X+ /*    directly.  This module is _never_ placed in an overlay so        */
  1634. X+ /*    calls via pointers to these functions will not cause difficulties.  */
  1635. X+ /*                                        */
  1636. X+ /****************************************************************************/
  1637. X+ 
  1638. X+ #ifdef OVERLAY
  1639. X+ 
  1640. X+ /* ### apply.c ### */
  1641. X+ #undef dig
  1642. X+ #undef doapply
  1643. X+ #undef dojump
  1644. X+ #undef dorub
  1645. X+ 
  1646. X+ int dig()     { return dig_();     }
  1647. X+ int doapply() { return doapply_(); }
  1648. X+ int dojump()  { return dojump_();  }
  1649. X+ int dorub()   { return dorub_();   }
  1650. X+ 
  1651. X+ 
  1652. X+ /* ### cmd.c ### */
  1653. X+ #undef doextcmd
  1654. X+ #undef doextlist
  1655. X+ 
  1656. X+ #ifdef POLYSELF
  1657. X+ #undef domonability
  1658. X+ #endif /* POLYSELF */
  1659. X+ 
  1660. X+ #undef timed_occupation
  1661. X+ 
  1662. X+ #if defined(WIZARD) || defined(EXPLORE_MODE)
  1663. X+ #undef wiz_attributes
  1664. X+ #endif
  1665. X+ 
  1666. X+ #ifdef WIZARD
  1667. X+ #undef wiz_detect
  1668. X+ #undef wiz_genesis
  1669. X+ #undef wiz_identify
  1670. X+ #undef wiz_level_tele
  1671. X+ #undef wiz_map
  1672. X+ #undef wiz_where
  1673. X+ #undef wiz_wish
  1674. X+ #endif
  1675. X+ 
  1676. X+ int doextcmd()         { return doextcmd_();         }
  1677. X+ int doextlist()        { return doextlist_();        }
  1678. X+ 
  1679. X+ #ifdef POLYSELF
  1680. X+ int domonability()     { return domonability_();     }
  1681. X+ #endif /* POLYSELF */
  1682. X+ 
  1683. X+ int timed_occupation() { return timed_occupation_(); }
  1684. X+ 
  1685. X+ #if defined(WIZARD) || defined(EXPLORE_MODE)
  1686. X+ int wiz_attributes()   { return wiz_attributes_();   }
  1687. X+ #endif
  1688. X+ 
  1689. X+ #ifdef WIZARD
  1690. X+ int wiz_detect()       { return wiz_detect_();       }
  1691. X+ int wiz_genesis()      { return wiz_genesis_();      }
  1692. X+ int wiz_identify()     { return wiz_identify_();     }
  1693. X+ int wiz_level_tele()   { return wiz_level_tele_();   }
  1694. X+ int wiz_map()          { return wiz_map_();          }
  1695. X+ int wiz_where()        { return wiz_where_();        }
  1696. X+ int wiz_wish()         { return wiz_wish_();         }
  1697. X+ #endif
  1698. X+ 
  1699. X+ 
  1700. X+ /* ### do.c ### */
  1701. X+ #undef doddrop
  1702. X+ #undef dodown
  1703. X+ #undef dodrop
  1704. X+ #undef donull
  1705. X+ #undef doup
  1706. X+ #undef dowipe
  1707. X+ #undef drop
  1708. X+ #undef wipeoff
  1709. X+ 
  1710. X+ int doddrop()             { return doddrop_(); }
  1711. X+ int dodown()              { return dodown_();  }
  1712. X+ int dodrop()              { return dodrop_();  }
  1713. X+ int donull()              { return donull_();  }
  1714. X+ int doup()                { return doup_();    }
  1715. X+ int dowipe()              { return dowipe_();  }
  1716. X+ int drop(obj)
  1717. X+ register struct obj *obj; { return drop_(obj); }
  1718. X+ int wipeoff()             { return wipeoff_(); }
  1719. X+ 
  1720. X+ 
  1721. X+ /* ### do_name.c ### */
  1722. X+ #undef ddocall
  1723. X+ #undef do_mname
  1724. X+ 
  1725. X+ int ddocall()  { return ddocall_();  }
  1726. X+ int do_mname() { return do_mname_(); } 
  1727. X+ 
  1728. X+ 
  1729. X+ /* ### do_wear.c ### */
  1730. X+ 
  1731. X+ /* ### do_wear.c ### */
  1732. X+ #undef Armor_off
  1733. X+ #undef Boots_off
  1734. X+ #undef Gloves_off
  1735. X+ #undef Helmet_off
  1736. X+ #undef Armor_on
  1737. X+ #undef Boots_on
  1738. X+ #undef Gloves_on
  1739. X+ #undef Helmet_on
  1740. X+ #undef doddoremarm
  1741. X+ #undef doputon
  1742. X+ #undef doremring
  1743. X+ #undef dotakeoff
  1744. X+ #undef dowear
  1745. X+ #undef select_off
  1746. X+ #undef take_off
  1747. X+ 
  1748. X+ int Armor_off()   { return Armor_off_();   }
  1749. X+ int Boots_off()   { return Boots_off_();   }
  1750. X+ int Gloves_off()  { return Gloves_off_();  }
  1751. X+ int Helmet_off()  { return Helmet_off_();  }
  1752. X+ /* int Armor_on()    { return Armor_on_();    } */
  1753. X+ int Boots_on()    { return Boots_on_();    }
  1754. X+ int Gloves_on()   { return Gloves_on_();   }
  1755. X+ int Helmet_on()   { return Helmet_on_();   }
  1756. X+ int doddoremarm() { return doddoremarm_(); }
  1757. X+ int doputon()     { return doputon_();     }
  1758. X+ int doremring()   { return doremring_();   }
  1759. X+ int dotakeoff()   { return dotakeoff_();   }
  1760. X+ int dowear()      { return dowear_();      }
  1761. X+ int select_off(otmp) struct obj *otmp; { return select_off_(otmp); }
  1762. X+ int take_off()    { return take_off_();    }
  1763. X+ 
  1764. X+ 
  1765. X+ /* ### dokick.c ### */
  1766. X+ #undef dokick
  1767. X+ 
  1768. X+ int dokick() { return dokick_(); }
  1769. X+ 
  1770. X+ 
  1771. X+ /* ### dothrow.c ### */
  1772. X+ #undef dothrow
  1773. X+ 
  1774. X+ int dothrow() { return dothrow_(); }
  1775. X+ 
  1776. X+ 
  1777. X+ /* ### eat.c ### */
  1778. X+ #undef Hear_again
  1779. X+ #undef Meatdone
  1780. X+ #undef doeat
  1781. X+ #undef eatfood
  1782. X+ #undef opentin
  1783. X+ #undef unfaint
  1784. X+ 
  1785. X+ int Hear_again()  { return Hear_again_(); }
  1786. X+ int Meatdone()    { return Meatdone_();   }
  1787. X+ int doeat()       { return doeat_();      }
  1788. X+ int eatfood()     { return eatfood_();    }
  1789. X+ int opentin()     { return opentin_();    }
  1790. X+ int unfaint()     { return unfaint_();    }
  1791. X+ 
  1792. X+ 
  1793. X+ /* ### end.c ### */
  1794. X+ #undef done2
  1795. X+ 
  1796. X+ int done2() { return done2_(); }
  1797. X+ 
  1798. X+ 
  1799. X+ /* ### engrave.c ### */
  1800. X+ #undef doengrave
  1801. X+ 
  1802. X+ int doengrave() { return doengrave_(); }
  1803. X+ 
  1804. X+ 
  1805. X+ /* ### hack.c ### */
  1806. X+ #undef dopickup
  1807. X+ #undef identify
  1808. X+ 
  1809. X+ int dopickup() { return dopickup_(); }
  1810. X+ int identify(otmp) struct obj *otmp; { return identify_(otmp); }
  1811. X+ 
  1812. X+ 
  1813. X+ /* ### invent.c ### */
  1814. X+ #undef ckunpaid
  1815. X+ #undef ddoinv
  1816. X+ #undef dolook
  1817. X+ #undef dopramulet
  1818. X+ #undef doprarm
  1819. X+ #undef doprgold
  1820. X+ #undef doprring
  1821. X+ #undef doprtool
  1822. X+ #undef doprwep
  1823. X+ #undef dotypeinv
  1824. X+ 
  1825. X+ int ckunpaid(obj) struct obj *obj; { return ckunpaid_(obj); }
  1826. X+ int ddoinv()     { return ddoinv_();     }
  1827. X+ int dolook()     { return dolook_();     }
  1828. X+ int dopramulet() { return dopramulet_(); }
  1829. X+ int doprarm()    { return doprarm_();    }
  1830. X+ int doprgold()   { return doprgold_();   }
  1831. X+ int doprring()   { return doprring_();   }
  1832. X+ int doprtool()   { return doprtool_();   }
  1833. X+ int doprwep()    { return doprwep_();    }
  1834. X+ int dotypeinv()  { return dotypeinv_();  }
  1835. X+ 
  1836. X+ 
  1837. X+ /* ### ioctl.c ### */
  1838. X+ /*
  1839. X+ #ifdef UNIX
  1840. X+ #ifdef SUSPEND
  1841. X+ #undef dosuspend
  1842. X+ 
  1843. X+ int dosuspend() { return dosuspend_(); }
  1844. X+ #endif
  1845. X+ #endif
  1846. X+ */
  1847. X+ 
  1848. X+ 
  1849. X+ /* ### lock.c ### */
  1850. X+ #undef doclose
  1851. X+ #undef doforce
  1852. X+ #undef doopen
  1853. X+ #undef forcelock
  1854. X+ #undef picklock
  1855. X+ 
  1856. X+ int doclose()   { return doclose_();   }
  1857. X+ int doforce()   { return doforce_();   }
  1858. X+ int doopen()    { return doopen_();    }
  1859. X+ int forcelock() { return forcelock_(); }
  1860. X+ int picklock()  { return picklock_();  }
  1861. X+ 
  1862. X+ 
  1863. X+ /* ### o_init.c ### */
  1864. X+ #undef dodiscovered
  1865. X+ 
  1866. X+ int dodiscovered() { return dodiscovered_(); }
  1867. X+ 
  1868. X+ 
  1869. X+ /* ### objnam.c ### */
  1870. X+ #undef doname
  1871. X+ #undef xname
  1872. X+ 
  1873. X+ char *doname(obj) struct obj *obj; { return doname_(obj); }
  1874. X+ char *xname(obj)  struct obj *obj; { return xname_(obj); }
  1875. X+ 
  1876. X+ 
  1877. X+ /* ### options.c ### */
  1878. X+ #undef doset
  1879. X+ #undef dotogglepickup
  1880. X+ 
  1881. X+ int doset()          { return doset_();         }
  1882. X+ int dotogglepickup() { return dotogglepickup_(); }
  1883. X+ 
  1884. X+ 
  1885. X+ /* ### pager.c ### */
  1886. X+ #undef dohelp
  1887. X+ #undef dohistory
  1888. X+ #undef dowhatdoes
  1889. X+ #undef dowhatis
  1890. X+ #ifdef UNIX
  1891. X+ #ifdef SHELL
  1892. X+ #undef dosh
  1893. X+ 
  1894. X+ int dosh()       { return dosh_();       }
  1895. X+ #endif
  1896. X+ #endif
  1897. X+ 
  1898. X+ int dohelp()     { return dohelp_();     }
  1899. X+ int dohistory()  { return dohistory_();  }
  1900. X+ int dowhatdoes() { return dowhatdoes_(); }
  1901. X+ int dowhatis()   { return dowhatis_();   }
  1902. X+ 
  1903. X+ 
  1904. X+ /* ### pickup.c ### */
  1905. X+ #undef ck_bag
  1906. X+ #undef ck_container
  1907. X+ #undef doloot
  1908. X+ #undef in_container
  1909. X+ #undef out_container
  1910. X+ 
  1911. X+ int ck_bag()  { return ck_bag_();  }
  1912. X+ int ck_container(obj)  struct obj *obj; { return ck_container_(obj); }
  1913. X+ int doloot() { return doloot_(); }
  1914. X+ int in_container(obj)  struct obj *obj; { return in_container_(obj); }
  1915. X+ int out_container(obj) struct obj *obj; { return out_container_(obj); }
  1916. X+ 
  1917. X+ 
  1918. X+ /* ### potion.c ### */
  1919. X+ #undef dodrink
  1920. X+ #undef dodip
  1921. X+ 
  1922. X+ int dodrink() { return dodrink_(); }
  1923. X+ int dodip()   { return dodip_();   }
  1924. X+ 
  1925. X+ 
  1926. X+ /* ### pray.c ### */
  1927. X+ #undef doturn
  1928. X+ #ifdef THEOLOGY
  1929. X+ #undef dopray
  1930. X+ #undef dosacrifice
  1931. X+ 
  1932. X+ int dopray()      { return dopray_();      }
  1933. X+ int dosacrifice() { return dosacrifice_(); }
  1934. X+ #endif /* THEOLOGY */
  1935. X+ 
  1936. X+ int doturn()      { return doturn_();      }
  1937. X+ 
  1938. X+ 
  1939. X+ /* ### pri.c ### */
  1940. X+ #undef doredraw
  1941. X+ 
  1942. X+ int doredraw()    { return doredraw_(); }
  1943. X+ 
  1944. X+ 
  1945. X+ /* ### read.c ### */
  1946. X+ #undef doread
  1947. X+ 
  1948. X+ int doread() { return doread_(); }
  1949. X+ 
  1950. X+ 
  1951. X+ /* ### save.c ### */
  1952. X+ #undef dosave
  1953. X+ 
  1954. X+ int dosave() { return dosave_(); }
  1955. X+ 
  1956. X+ 
  1957. X+ /* ### search.c ### */
  1958. X+ #undef doidtrap
  1959. X+ #undef dosearch
  1960. X+ 
  1961. X+ int doidtrap() { return doidtrap_(); }
  1962. X+ int dosearch() { return dosearch_(); }
  1963. X+ 
  1964. X+ 
  1965. X+ /* ### shk.c ### */
  1966. X+ #undef dopay
  1967. X+ 
  1968. X+ int dopay() { return dopay_(); }
  1969. X+ 
  1970. X+ 
  1971. X+ /* ### sit.c ### */
  1972. X+ #undef dosit
  1973. X+ 
  1974. X+ int dosit() { return dosit_(); }
  1975. X+ 
  1976. X+ 
  1977. X+ /* ### sounds.c ### */
  1978. X+ #undef dotalk
  1979. X+ 
  1980. X+ int dotalk() { return dotalk_(); }
  1981. X+ 
  1982. X+ 
  1983. X+ /* ### spell.c ### */
  1984. X+ #ifdef SPELLS
  1985. X+ #undef learn
  1986. X+ #undef docast
  1987. X+ #undef dovspell
  1988. X+ 
  1989. X+ int learn() { return learn_(); }
  1990. X+ int docast()   { return docast_();   }
  1991. X+ int dovspell() { return dovspell_(); }
  1992. X+ #endif
  1993. X+ 
  1994. X+ 
  1995. X+ /* ### steal.c ### */
  1996. X+ #undef stealarm
  1997. X+ 
  1998. X+ int stealarm() { return stealarm_(); }
  1999. X+ 
  2000. X+ 
  2001. X+ /* ### topl.c ### */
  2002. X+ #undef doredotopl
  2003. X+ 
  2004. X+ int doredotopl() { return doredotopl_(); }
  2005. X+ 
  2006. X+ 
  2007. X+ /* ### trap.c ### */
  2008. X+ #undef dotele
  2009. X+ #undef dountrap
  2010. X+ #undef float_down
  2011. X+ 
  2012. X+ int dotele()     { return dotele_();     }
  2013. X+ int dountrap()   { return dountrap_();   }
  2014. X+ int float_down() { return float_down_(); }
  2015. X+ 
  2016. X+ 
  2017. X+ /* ### version.c ### */
  2018. X+ #undef doversion
  2019. X+ 
  2020. X+ int doversion() { return doversion_(); }
  2021. X+ 
  2022. X+ 
  2023. X+ /* ### wield.c ### */
  2024. X+ #undef dowield
  2025. X+ 
  2026. X+ int dowield() { return dowield_(); }
  2027. X+ 
  2028. X+ 
  2029. X+ /* ### zap.c ### */
  2030. X+ #undef bhitm
  2031. X+ #undef bhito
  2032. X+ #undef dozap
  2033. X+ 
  2034. X+ int bhitm(mtmp, otmp) struct monst *mtmp; struct obj *otmp;
  2035. X+     { return bhitm_(mtmp, otmp); }
  2036. X+ int bhito(obj, otmp) struct obj *obj, *otmp; { return bhito_(obj,  otmp); }
  2037. X+ int dozap() { return dozap_(); }
  2038. X+ #endif /* OVERLAY */
  2039. END_OF_FILE
  2040. if test 58568 -ne `wc -c <'patches06d'`; then
  2041.     echo shar: \"'patches06d'\" unpacked with wrong size!
  2042. fi
  2043. # end of 'patches06d'
  2044. fi
  2045. echo shar: End of archive 2 \(of 15\).
  2046. cp /dev/null ark2isdone
  2047. MISSING=""
  2048. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  2049.     if test ! -f ark${I}isdone ; then
  2050.     MISSING="${MISSING} ${I}"
  2051.     fi
  2052. done
  2053. if test "${MISSING}" = "" ; then
  2054.     echo You have unpacked all 15 archives.
  2055.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2056. else
  2057.     echo You still need to unpack the following archives:
  2058.     echo "        " ${MISSING}
  2059. fi
  2060. ##  End of shell archive.
  2061. exit 0
  2062.